using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameStateManagement;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using GameStateManagementSample.FrameWork.Sprite;

namespace GameStateManagementSample.Screens
{
    class AboutScreen : GameScreen
    {
        #region  Fields
        Texture2D m_TAbout;
        ContentManager m_Content;        
        InputAction pauseAction;
           
#endregion
        
#region Initialization
        public AboutScreen()
        {
            TransitionOnTime = TimeSpan.FromSeconds(0.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);
            pauseAction = new InputAction(
                new Buttons[] { Buttons.Start, Buttons.Back },
                new Keys[] { Keys.Escape },
                true);
            
        }
        public override void Activate(bool instancePreserved)
        {
            if (!instancePreserved)
            {
                if (m_Content == null)
                {
                    m_Content = new ContentManager(ScreenManager.Game.Services, "Content");
                    ScreenManager.Game.ResetElapsedTime();
                    m_TAbout = m_Content.Load<Texture2D>(@"Image/about");
                }
            }
        }
        public override void Deactivate()
        {
            base.Deactivate();
        }
        public override void Unload()
        {
            base.Unload();
        }
#endregion
#region update anhd draw
        protected virtual void OnCancel()
        {
            ExitScreen();            
        }
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
          
        }
        public override void HandleInput(Microsoft.Xna.Framework.GameTime gameTime, InputState input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            PlayerIndex player;
            if (pauseAction.Evaluate(input, ControllingPlayer, out player))
            {
                OnCancel();
            }
            TouchCollection touches = input.TouchState;

            foreach (TouchLocation touch in touches)
            {
                if (touch.State == TouchLocationState.Pressed)
                {
                    
                               
                }
            }
        }
        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            float alpha = MathHelper.Lerp(1f - TransitionAlpha, 1f, TransitionAlpha / 2);
            ScreenManager.FadeBackBufferToBlack(1.0f-alpha);
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            spriteBatch.Begin();           
            spriteBatch.Draw(m_TAbout, new Vector2((TransitionPosition*200),0), Color.White * TransitionAlpha);
            spriteBatch.End();
            
        }
       
#endregion
    }
}
